package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.adapter.EditBatchInstallationEngineeringAdapter;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringConstructContentBean;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

import java.io.Serializable;
import java.util.List;


public class EditBatchInstallationEngineeringActivity1 extends Activity implements View.OnClickListener {
    private final String TAG = EditBatchInstallationEngineeringActivity.class.getSimpleName();
    private ImageView img_back;
    private TextView tv_title;
    private TextView btn_edit;
    private RelativeLayout rl_project_name;
    private ImageView img_project_select;
    private ListView lv;
    private LinearLayout ll_engineering_info_content;
    private TextView tv_project_name,tv_engineering_name,edt_completion_date,edt_dispath_order_person_colon,edt_dispath_order_time_colon,edt_receive_people_colon,edt_reception_time_colon;

    private EditBatchInstallationEngineeringAdapter adapter;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
            );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_edit_batch_installation_engineering1);

        init();
    }

    private void init() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        btn_edit = findViewById(R.id.btn_edit);
        rl_project_name = findViewById(R.id.rl_project_name);
        img_project_select = findViewById(R.id.img_project_select);
        lv = findViewById(R.id.lv_add_product);
        ll_engineering_info_content=findViewById(R.id.ll_engineering_info_content);
        tv_project_name=findViewById(R.id.tv_project_name);
        tv_engineering_name=findViewById(R.id.tv_engineering_name);
        edt_completion_date=findViewById(R.id.edt_completion_date);
        edt_dispath_order_person_colon=findViewById(R.id.edt_dispath_order_person_colon);
        edt_dispath_order_time_colon=findViewById(R.id.edt_dispath_order_time_colon);
        edt_receive_people_colon=findViewById(R.id.edt_receive_people_colon);
        edt_reception_time_colon=findViewById(R.id.edt_reception_time_colon);

        tv_title.setText(getResources().getText(R.string.batch_installation));
        img_back.setOnClickListener(this);
        btn_edit.setOnClickListener(this);

        img_project_select.setBackgroundResource(R.mipmap.arrow_down_icon);

        rl_project_name.setOnClickListener(this);
        img_project_select.setOnClickListener(this);


    }

    private void completionEdit() {
        Toast.makeText(this, "编辑成功", Toast.LENGTH_SHORT).show();
        finish();
    }

    // 项目名称/工程名称 收放
    private void showEngineeringInfoDialog() {
        if (ll_engineering_info_content.getVisibility() == View.VISIBLE) {
            ll_engineering_info_content.setVisibility(View.GONE);
            img_project_select.setBackgroundResource(R.mipmap.arrow_down_icon);
        } else {
            ll_engineering_info_content.setVisibility(View.VISIBLE);
            img_project_select.setBackgroundResource(R.mipmap.arrow_top);
        }
    }

    @Override
    public void onClick(View view) {
        TextView tv;
        Intent mIntent;
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_edit:
                completionEdit();
                break;
            // 项目名称/工程名称 收放
            case R.id.img_project_select:
                showEngineeringInfoDialog();
                break;

        }
    }

//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        switch (requestCode) {
//            case ConstantUtil.ADD_PRODUCT_INFOMATION:
//                if (data != null) {
//                    List<EngineeringConstructContentBean> dataLs = (List<EngineeringConstructContentBean>) data.getSerializableExtra(ConstantUtil.PRODUCTBEAN);
//                    datas = dataLs;
//                    adapter.setData(datas);
//                    adapter.notifyDataSetChanged();
//                }
//                break;
//            case ConstantUtil.ADD_PRODUCT_LIST:
//                if (data != null) {
//                    Bundle mBundle = data.getExtras();
//                    if (mBundle != null) {
//                        String start_date = mBundle.getString(ConstantUtil.KEY_1);
//                        String end_date = mBundle.getString(ConstantUtil.KEY_2);
//                        EngineeringConstructContentBean bean = datas.get(selectedPosition);
//                        bean.setStartDate(start_date);
//                        bean.setEndDate(end_date);
//                        adapter.setData(datas);
//                        adapter.notifyDataSetChanged();
//                    }
//                }
//                break;
//        }
//        super.onActivityResult(requestCode, resultCode, data);
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();


    }
}
